The Game of Life

A 2 dimensional matrix of cells represents the world.  Each cell is either occupied by an organism or is empty. Rules for going from present to next world:
	If a cell has 0,1,4,5,6,7 or 8 occupied neighbours itdiesfrom loneliness or overpopulation at the next time step
	If an uncoppied cell has exactly 3 occupied neighbours it becomes occupied,that is a new life is born at the next time step
	If a cell has 2 neighbours then nothing happens to it

m1=(({{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}}))

Level[m1,{1}]

RotateLeft[m1,{0,1}]//MatrixForm

RotateLeft[m1,{0,-1}]//MatrixForm

Neighbours[m_ /; MatrixQ[m]] := 
    RotateLeft[m,{0,1}] + RotateLeft[m,{0,-1}] + RotateLeft[m,{1,0}] + 
    RotateLeft[m, {-1,0}] + RotateLeft[m, {1,1}] + RotateLeft[m, {1,-1}] + 
    RotateLeft[m, {-1,1}] + RotateLeft[m, {-1,-1}]

Neighbours[m1] // MatrixForm

Neighbours[m_ /; MatrixQ[m], n_Integer] := 
(Neighbours[m,n] = 1-(Neighbours[m]-n 
	/. (x_Integer /; x!=0 -> 1)))

m1//MatrixForm

Neighbours[m1,2] // MatrixForm

Neighbours[m1,3] // MatrixForm

m1* Neighbours[m1,2] //MatrixForm

m1 *Neighbours[m1,3] //MatrixForm

(1-m1)* Neighbours[m1,3] //MatrixForm

LifeStep [m_ /; MatrixQ[m]] := (LifeStep[m] =
	m Neighbours[m,2] + m Neighbours[m,3] + (1-m) Neighbours[m,3])

LifeStep[m1] // MatrixForm

LifeStep[LifeStep[m1]] // MatrixForm

m1

ShowLifeMatrix[m_ /; MatrixQ[m]] := 
Show[MatrixPlot[1-m,ColorFunction->(RGBColor[1,#, 1]&),Mesh->True, Frame->False]]

ShowLifeMatrix[LifeStep[m1]]

ij=Table[RandomInteger[{1,20},2],{30}]

m1=Table[0, {20}, {20}]

Map[ (m1[[First[#],Last[#]]]=1)&, ij]

m1[[15]][[9]]

m1

Table[ShowLifeMatrix[Nest[LifeStep, m1, i]], {i,0,5}]

m2=RandomInteger[{0,1},{20,20}]

Table[ShowLifeMatrix[Nest[LifeStep, m2, i]], {i,0,5}]

Package

BeginPackage["games`life`"]

Neighbours::usage = "Neighbours[m] returns a matrix of the sum of the values 
of the neighbours element.
Neighbours[m, n] returns a matrix with the items which have n neighbours set 
to 1, the rest set to 0."

LifeStep::usage = "LifeStep[m] Performs one step following Conway's Game of 
Life rules on matrix m, and returns the result as a matrix."

ShowLifeMatrix::usage="ShowLifeMatrix Shows a plot of the matrix."

Begin["`Private`"]

Neighbours[m_ /; MatrixQ[m]] := 
    RotateLeft[m,{0,1}] + RotateLeft[m,{0,-1}] + RotateLeft[m,{1,0}] + 
    RotateLeft[m, {-1,0}] + RotateLeft[m, {1,1}] + RotateLeft[m, {1,-1}] + 
    RotateLeft[m, {-1,1}] + RotateLeft[m, {-1,-1}]

Neighbours[m_ /; MatrixQ[m], n_Integer] := 
  (Neighbours[m,n] = 1-(Neighbours[m]-n /. (x_Integer /; x!=0 -> 1))) 

LifeStep [m_ /; MatrixQ[m]] := (LifeStep[m] =
	m Neighbours[m,2] + m Neighbours[m,3] + (1-m) Neighbours[m,3])

ShowLifeMatrix[m_ /; MatrixQ[m]] := 
 Show[MatrixPlot[1 - m, ColorFunction -> (RGBColor[1, #, 1] &), 
   Mesh -> True, Frame -> False]]

End[]

EndPackage[]

Test Package

m2=RandomInteger[{0,1},{20,20}];
tbl=Table[ShowLifeMatrix[Nest[LifeStep,m2, i]],{i,0,10}]

Length[tbl]

m2